<?php
echo PHP_VERSION, PHP_EOL;
// START@#2017-05-#


// START@#2017-05-#
$arr = [
    51 => [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7],
    [6, 8, 9],
    [9, 10, 11]
];

var_dump(array_column($arr, null, 1), array_column($arr, 1, -1));
exit;
$villagePattern = '/(?=(?:乡|镇|街道|^))(.+[村庄])/u';
$address = '七都乡黄厝村路里弄4号';
if(preg_match($villagePattern, $address, $matched)){
    $address = explode($matched[1], $address)[0] . $matched[1];
}

var_dump($matched);

echo $address, PHP_EOL;

exit();
// END@#2017-05-15#


// START@#2017-05-10#

class a
{
    private $t;

    public function test()
    {
        // $z = &$this->t = [];
        $z[2] = 11;
        $z['asf'] = 122;
        var_dump($z, $this->t);
    }
}

(new a)->test();

exit;


// assert('1 === 1') && println('OK');

// exit;

//接口调试
// {"app_id":"50019","ts":1494311922238,"sign":"82e60900112631b03975975983a2c023","data":{"waybill":"3312207560499","province":"鄂州","city":"3","district":"15","address":"上海中转包","from_province":"上海中转包","from_city":"上海市","from_district":"上海区"}}
$api = '/v1/addressLib/querySortingCode';
$ts = 1494392563368;
$appId = '50019';
$sign = '6e81d59a6e7ede077687819a6bd626b8';
echo md5($appId.$api.$ts.'6182047ef23852e8ea7d381d6ad0eed5aa48bb31'), PHP_EOL, $sign;

exit;
// END@#2017-05-10#
//
// START@#2017-05-09#
$inputAddress = [
    'province' => '',
    'city' => '北京',
];

if(preg_match('/^(北京|上海|天津|重庆)市?$/u', $inputAddress['province'] ?: $inputAddress['city'], $matched) && ($inputAddress['city'] === '' || $inputAddress['province'] === '')){
    $inputAddress['province'] = $matched[1];
    $inputAddress['city'] = $matched[1] . '市';
}
var_dump($inputAddress, $matched);
exit;
// END@#2017-05-09#


// START@#2017-05-08#
// PCRE UTF-8 mode with character class and non UTF-8 mode with alternative performance compitition

$str = '是放假回家咯是否还卡忻州地区，春秋时大部分属晋地，战国属赵，秦汉属太原，雁门，太平等郡，隋为新兴郡、雁门郡，唐、五代、宋为忻州雁门郡，金、元、明、清为忻州、代州、保德州，民国初属雁门道，后分别属山西第一、第二专员公署。中华人民共和国成立后成立忻县专区。1958年底与雁北专区合并为晋北专区，1961年复置忻县专区。1970年改专区为地区，1978年改地区为行政公署。2000年6月14日，经国务院批准：撤销忻州地区和县级忻州市，设立地级忻州市。自然资源[编辑]忻州已探明储量的矿产达50余种，其中煤炭800亿吨，占全省的13%；铝土矿2.5亿吨，占全省的27%；铁矿18亿吨，占全省的48%；金矿1.9万公斤，占全省的74%；钛矿7600万吨，为全国第二大矿床。是否政府看看么还卡手反拉是否，啊我们过来了看我估计是大姑娘了考试大纲asfha啊师傅好卡是发顺丰快件ask根据计划和金额就啊师傅感觉啊开始就发了三个接口啦啦啦';

function buildRandomStrArr(int $num, string $source)
{
    $strArr = [];
    $arr = preg_split('//u', $source, -1, PREG_SPLIT_NO_EMPTY);
    $count = count($arr);
    while($num-- > 0){
        $num % 5 || shuffle($arr);
        $strArr[] = implode('', array_slice($arr, $start = random_int(0, $count -5), random_int(1, $count) - $start));
    }
    return $strArr;
}

$i  = $j = 2000;
$strArr = array_filter(buildRandomStrArr(1000, $str));

$pattern = '~(?:城|市|省)$~';
$timeLog['start'] = microtime(true);
while ($i-- > 0) {
    foreach ($strArr as $name) {
        preg_replace($pattern, '', $name);
    }
}
$timeLog['cost'] = ($timeLog['end'] = microtime(true)) - $timeLog['start'];

$timeLog['startU'] = microtime(true);
$patternUtf8Mode = '~[城市省]$~u';
while ($j-- > 0) {
    foreach ($strArr as $name) {
        preg_replace($pattern, '', $name);
    }
}
$timeLog['costU'] = ($timeLog['endU'] = microtime(true)) - $timeLog['startU'];


printf('start@%s ,end@%s, cost:%s'.PHP_EOL, $timeLog['start'], $timeLog['end'], $timeLog['cost']);
printf('start@%s ,end@%s, cost:%s'.PHP_EOL, $timeLog['startU'], $timeLog['endU'], $timeLog['costU']);





// var_dump($strArr);

exit;

foreach ($names as $val) {
    echo base64_encode($val),PHP_EOL;
}
//&#x57CE;&#x5E02;&#x7701;
$ret = array_map(function($name) use($pattern){
    return ;
}, $names);

foreach ($ret as $val) {
    echo base64_encode($val),PHP_EOL;
}

exit();
// END@#2017-05-08#


// START@#2017-05-04

$scriptName = 'echo.php';
$dir = 'D:\\MyDocuments\\Desktop\\';
$arr = [];
$arr = array_map(function($val) use($dir){
    return $dir . $val;
}, array_pad($arr, 5, $scriptName));

$params = 'hello';
// $commands = array_map(function($script) use($params){
//     return sprintf('start php %s %s', $script, $params);
// }, $arr);
$commands = array_walk($arr, function($script) use($params){
    $output = $return = [];
    exec(sprintf('start php %s %s', $script, $params), $output, $return);
});
echo implode("\n", $commands),PHP_EOL;
// echo exec(implode("\n", $commands));
$str =<<<COMMANDS
start php D:\MyDocuments\Desktop\echo.php hello
start php D:\MyDocuments\Desktop\echo.php hello
start php D:\MyDocuments\Desktop\echo.php hello
start php D:\MyDocuments\Desktop\echo.php hello
start php D:\MyDocuments\Desktop\echo.php hello
COMMANDS;
// var_dump(shell_exec($str));
// END@#2017-05-04




function println($str)
{
    print(rtrim($str, PHP_EOL) . PHP_EOL);
}
